*************************************************************
*Table A11: Robots and students’ CZ-specific migration flows*
*************************************************************

*Education
use "$final_data_outcomes/czone_Students.dta", clear

*Migration
rename czone toczone
merge 1:m toczone year using "$final_data_outcomes/czone_StudentMigrantsCombi.dta", assert(1 3) nogenerate

*Automation
merge m:1 fromczone year using "$final_data_automation/czones_ExposureRobotsOrigin.dta",  nogenerate
merge m:1 toczone year using "$final_data_automation/czones_ExposureRobotsDestination.dta",  nogenerate

*Covariates
merge m:1 toczone using "$final_data_covariates/toczone1990_Covariates.dta", nogenerate //beginning of period
merge m:1 fromczone using "$final_data_covariates/fromczone1990_Covariates.dta", nogenerate //beginning of period

*Keep only periods of interest
keep if year<=2000

/*
*Standardization
foreach var of varlist d_shareStudentsN? {
quiet sum `var'
quiet gen `var'_sd = (`var'-`r(mean)')/`r(sd)'
}

foreach var of varlist expof_*_destination expof_*_origin {
quiet sum `var'
quiet gen `var'_sd = (`var'-`r(mean)')/`r(sd)'
}
*/

*Increase size for coefficients in table
gen d_shareStudentsN4_1000 = d_shareStudentsN4*1000

eststo clear
eststo: ivreghdfe d_shareStudentsN4_1000 (expof_us_adj_destination = expof_euro7_destination) $controls_combi_1990 if toczone!=fromczone [w=ipums_pop_1990_d], absorb(division_d##division_o##year) cluster(statefip_d)
eststo: ivreghdfe d_shareStudentsN4_1000 (expof_us_adj_origin = expof_euro7_origin) $controls_combi_1990 if toczone!=fromczone [w=ipums_pop_1990_d], absorb(division_d##division_o##year) cluster(statefip_d)
eststo: ivreghdfe d_shareStudentsN4_1000 (expof_us_adj_destination expof_us_adj_origin = expof_euro7_destination expof_euro7_origin) $controls_combi_1990 if toczone!=fromczone [w=ipums_pop_1990_d], absorb(division_d##division_o##year) cluster(statefip_d)

estout using "$tables_appendix/Table A10.tex", style(tex) ///
varlabels(expof_us_adj_destination "$\text{US robot exposure}_{cz}$" expof_us_adj_origin "\text{US robot exposure}_{cz_o}") ///
cells(b(fmt(%9.3f) star) se(par)) nolabel replace mlabels(none) collabels(none) starlevels(\$^{*}\$ .1 \$^{**}\$ .05 \$^{***}\$ .01) /// 
keep(expof_us_adj_destination expof_us_adj_origin) ///
order(expof_us_adj_destination expof_us_adj_origin)

